<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    div {
      width: 300px;
      height: 40px;
      border: 1px solid rgb(255, 192, 200);
      text-align: center;
      line-height: 40px;
    }
  </style>
</head>

<body>
  <div></div>

  <script>


    // 实现电子时间效果，在div里显示 现在是2024年11月21日 10:12:07 格式的时间
    function getTime() {
      const date = new Date();
      const year = date.getFullYear();
      const month = date.getMonth();
      const day = date.getUTCDate();
      const h = date.getHours();
      const m = date.getMinutes();
      const s = date.getSeconds();
      let str = `现在是${year}年${month}月${day}日${h}:${m}:${s}`
      document.querySelector('div').innerHTML = str;
    }
    getTime()
    setInterval(getTime, 1000)

  </script>
</body>

</html>